﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using Microsoft.Win32;

namespace ADAuthTest
{
    public class RemoteManagement
    {
        public RemoteManagement()
        {
            
            //string strHost = "localhost"; //主机名
            //string regMain = @"Network";
            //string[] subKey = { "DisplayName" };

            //ManagementClass mClass = new ManagementClass(@"//" + strHost + @"/root/DEFAULT:StdRegProv");
            //object[] method_args = new object[] { "HKEY_CURRENT_USER", regMain, null };
            //object result= mClass.InvokeMethod("RemotePath", method_args);

            //ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From Win32_LogicalDisk ");

            //foreach (ManagementObject mo in query.Get())
            //{
            //    Console.WriteLine(mo["DriveType"].ToString() + mo.Path);
            //}
            ConnectionOptions options = new ConnectionOptions();
            options.Username = "ceibs\\moss2010"; // "ceibs\\FacTest3";
            options.Password = "JDP93fv";// "abc.123";
            //options.Authority = "ceibs.edu";
            try
            {
                ManagementScope scope = new ManagementScope(@"\\172.16.0.171\root\RSOP\Computer");
                scope.Options = options;
                scope.Connect();
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope
                    , new ObjectQuery("SELECT * FROM RSOP_IEConnectionSettingsLink  "));
                ManagementObjectCollection moList = searcher.Get();
                if (moList.Count > 0)
                {
                    foreach (ManagementObject o in searcher.Get())
                    {
                        //Console.WriteLine(o);
                        if (o.Properties.Count > 0)
                        {
                            foreach (var item in o.Properties)
                            {
                                Console.WriteLine("Name:{0} Value:{1}", item.Name, item.Value);
                            }
                        }
                    }
                }
                Console.WriteLine("Done");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }


    }
}
